package com.itheima.service;


import com.itheima.dao.BaseStudentDao;
import com.itheima.dao.otherStudentDao;
import com.itheima.domain.Student;
import com.itheima.factory.StudentDaoFactory;

public class StudentService {
   private BaseStudentDao stuDao =StudentDaoFactory.getStudentDao();
    public boolean addStudent(Student stu) {

        return stuDao.addStudent(stu);
    }

    public Student[] selectStudent() {
        Student[] stuD= stuDao.findAllStudent();
        boolean flag=false;
        for (int i = 0; i < stuD.length; i++) {
            Student stu = stuD[i];
            if(stu!=null){
                flag=true;
                break;
            }
        }
        if(flag){
            return stuD;
        }else {
            return null;
        }
    }

    public boolean isExists(String sid) {
        Student []stus =stuDao.findAllStudent();
        boolean exists=false;
        for (int i = 0; i < stus.length; i++) {
                Student stufind= stus[i];
                if(stufind!=null&&stufind.getSid().equals(sid)){
                    exists=true;
                    break;
                }
        }
        return exists;
    }

    public void deletStudent(String sid) {
        stuDao.deletStudent(sid);
    }

    public void updateStudent(String sid, Student stu) {
        stuDao.updateStudent( sid,  stu);
    }
}
